#include <sstream>
#include <stdexcept>

#include <boost/archive/binary_iarchive.hpp>
#include <boost/archive/binary_oarchive.hpp>
#include <boost/serialization/vector.hpp>

namespace boost_pack {
template <typename T>
std::string serialize(const T &t) {
    std::stringstream ss;
    boost::archive::binary_oarchive out_archive(ss);
    try {
        out_archive << t;
        return ss.str();
    } catch (const boost::archive::archive_exception &e) {
        throw std::runtime_error(std::string(e.what()));
    }
}

template <typename T>
T deserialize(const std::string &s) {
    T res;
    std::istringstream iss(s);
    boost::archive::binary_iarchive in_archive(iss);
    try {
        in_archive >> res;
        return res;
    } catch (const boost::archive::archive_exception &e) {
        throw std::runtime_error(std::string(e.what()));
    }
}
} // namespace boost_pack
